#!/bin/bash

. /etc/init.d/functions

url_list=($1 $2 $3 $4 $5)
function wait() {
  echo -n "正在准备，五秒后执行检查操作.";
  for ((i=0;i<5;i++))
  do
    echo -n ".";sleep 1
  done
  echo
}

function check_url() {
  wait
  for ((i=0;i<`echo ${#url_list[@]}`;i++))
  do 
    wget -o /dev/null  --tries=2  -T 3 --spider ${url_list[$i]} > /dev/null 2>&1
    if [ $? -eq 0 ];then
       action "${url_list[$i]} is ok"  /bin/true
    else
       action "${url_list[$i]} is down" /bin/false
       echo -e "http://${url_list[$i]} is down,please check your server ASAP.\n\n\nBestRegards\nthank you" | mail -s "${url_list[$i]} is down" bushaoxun@wpic.co
    fi
    sleep 1
  done
}
main() {
  if [ $# -le 5 ];then
     while true
     do
       check_url
       sleep 10
     done
  else
     echo "最多输入五个url,请仔细检查输入的参数"
  fi
}

main "$@"
